<%@page import="youleche.com.controler.controler.PageDataForBussinessControler"%>
<%@page import="youleche.com.util.AESEncryptAndDecrypt"%>
<%@page import="youleche.com.common.ParamConfigParameters"%>
<%@page import="youleche.com.model.MUser"%>
<%@page import="youleche.com.business.BUser"%>
<%@page import="com.qq.connect.javabeans.qzone.UserInfoBean"%>
<%@page import="com.qq.connect.api.OpenID"%>
<%@page import="com.qq.connect.api.qzone.UserInfo"%>
<%@page import="com.qq.connect.oauth.Oauth"%>
<%@page import="com.qq.connect.javabeans.AccessToken"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="keywords" content="美乐车,电动车报价,自行车报价,出租自行车,出租电动车,美乐车租车，车辆售后服务" />
<meta name="description" content="美乐车, 美乐车网,美乐车租车，电动车报价,自行车报价，出租自行车，出租电动车，全国最大的车辆交易信息网站" />
<title>第三方登陆-美乐车网</title>
</head>
<%
	AccessToken tokenObj = (new Oauth()).getAccessTokenByRequest(request);
	if (tokenObj.getAccessToken().equals("")) {
		//out.println("accessToken is error!");
	} else {
		String accessToken = tokenObj.getAccessToken();
		String openID = new OpenID(accessToken).getUserOpenID();
		UserInfo qzoneUserInfo = new UserInfo(accessToken, openID);
		UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo();
		BUser userHandler = new BUser();
		MUser userInfo = userHandler.getUserByOpenID_A10(openID + "_" + accessToken);
		if(userInfo == null){
			//添加用户信息
			request.setAttribute("userName", userInfoBean.getNickname());
			request.setAttribute("A10", openID + "_" + accessToken);
			//跳转到登陆页面
			
			request.getRequestDispatcher("/loginData.jsp").forward(request, response);
		}else{
			ParamConfigParameters paramConfig = new ParamConfigParameters();
			String loginCode_KEY = paramConfig.getParameter("loginCode_KEY");
			try {
				session.setAttribute(userInfo.getUserName(), AESEncryptAndDecrypt.encrypt(userInfo.getUserName() + "^" + userInfo.getUserPassword(), loginCode_KEY));
				
				PageDataForBussinessControler.setCookie(response, "youleche.u", userInfo.getUserName());
				PageDataForBussinessControler.setCookie(response, "youleche.s", AESEncryptAndDecrypt.encrypt(userInfo.getUserName() + "^" +  userInfo.getUserPassword(), loginCode_KEY));
			} catch (Exception e) {
				e.printStackTrace();
			}

			//跳转到登陆页面
			request.getRequestDispatcher("/loginSuccess.jsp").forward(request, response);
		}
	}
%>
<body>

</body>
</html>